package kr.co.boogui.actions.reservation;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import kr.co.boogui.actions.ActionHandler;
import kr.co.boogui.dao.ReservationDAO;
import kr.co.boogui.service.MemberService;
import kr.co.boogui.service.ReservationService;

public class ReservationAction implements ActionHandler {
	@Override
	public String execute(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		String viewPage = "f|/WEB-INF/jsp/tiles/index.jsp";
		String method = req.getMethod();		
		if (MemberService.chkMember(req)) {
			if (method.equalsIgnoreCase("get")) {
				req.setAttribute("action", "../reservation/reservation.jsp");
				if (req.getParameter("movno")!=""){
					req.setAttribute("imgnum", req.getParameter("movno"));
				}
				ReservationService.displayMovie(req);
				ReservationService.readCinema(req);
				ReservationService.readDate(req);
			} else if (method.equalsIgnoreCase("post")) {				
				boolean r = ReservationService.regiReservation(req);
				boolean s = ReservationService.regiSales(req);
				boolean seat = ReservationService.regiSeat(req);
				HttpSession sess = req.getSession();
				String mno = (String) sess.getAttribute("mno");
				if (r && s && seat) {
					viewPage = "r|mypage.bi?mno=" + mno;
				}
			}			
		} else {
			req.setAttribute("action", "../member/loginchk.jsp");
		}
		return viewPage;
	}

}
